package cn.csbit.common;

import org.apache.log4j.LogManager;
import org.apache.log4j.xml.DOMConfigurator;

import java.io.File;

//系统的跟踪和提示等信息日志的统一处理，在这里
public final class Logger {
    static {
        String userDir = System.getProperty("user.dir");
        String configFilename = userDir + File.separator + "log4j.xml";
        File file = new File(configFilename);
        if (file.exists() && file.isFile() && file.canRead()) {
            DOMConfigurator.configure(configFilename);
        }
    }

    private static final org.apache.log4j.Logger logger = LogManager.getLogger(Logger.class);

    public static void info(Object message) {
        logger.info(message);
    }

    public static void info(String message) {
        logger.info(message);
    }

    public static void info(String message, Throwable t) {
        logger.info(message, t);
    }

    public static void debug(String message) {
        logger.debug(message);
    }

    public static void debug(String message, Throwable t) {
        logger.debug(message, t);
    }

    public static void warn(String message) {
        logger.warn(message);
    }

    public static void warn(String message, Throwable t) {
        logger.warn(message, t);
    }

    public static void error(String message) {
        logger.error(message);
        assert(false);
    }

    public static void error(String message, Throwable t) {
        logger.error(message, t);
        assert(false);
    }

    public static void fatal(String message) {
        logger.fatal(message);
        assert(false);
    }

    public static void fatal(String message, Throwable t) {
        logger.fatal(message, t);
        assert(false);
    }
}